package cn.wolfcode.web.controller;

import cn.wolfcode.domain.MenuCatalogue;
import cn.wolfcode.qo.MenuCatalogueObject;
import cn.wolfcode.service.IMenuCatalogueService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("/menuCatalogue")
public class MenuCatalogueController {

    @Autowired
    private IMenuCatalogueService menuCatalogueService;

    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") MenuCatalogueObject qo) {
        PageInfo<MenuCatalogue> pageInfo = menuCatalogueService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "menuCatalogue/list"; // /WEB-INF/views/menuCatalogue/list.ftl
    }

    @RequestMapping("/delete")
    public String delete(Long id) {

        if (id != null) {
            menuCatalogueService.delete(id);
        }
        return "redirect:/menuCatalogue/list"; // localhost/menuCatalogue/list
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MenuCatalogue menuCatalogue) {

        if (menuCatalogue.getId() == null) {
            menuCatalogueService.save(menuCatalogue);
        } else {
            menuCatalogueService.update(menuCatalogue);
        }
        return "redirect:/menuCatalogue/list"; // localhost/menuCatalogue/list
    }

    @RequestMapping("/updateStatus")
    public String updateStatus(Long id, int status) {

        menuCatalogueService.updateStatus(id, status);

        return "redirect:/menuCatalogue/list"; // localhost/appointment/list
    }

}
